﻿using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace LoggerNumTest
{
    public class NumPrint
    {
        private readonly ILogger<NumPrint> logger;

        public NumPrint(ILogger<NumPrint> logger)
        {
            this.logger = logger;
        }

        public void Print()
        {
            ThreadPool.QueueUserWorkItem(obj =>
            {
                var index = 0;
                object data = null;
                while(index < 5)
                {
                    logger.LogDebug("obj:{0}", data);
                    logger.LogDebug("datetime:{time}",DateTime.Now);
                    logger.LogWarning("list:{list}",new List<int>() { 1,2,3,4,5});
                    logger.LogWarning("listObj:{@listObj}",new List<Person>()
                    {
                        new Person(){Name="张三", Age = 18, Address="金水区"},
                        new Person(){Name="李四", Age = 22, Address="惠济区"},
                        new Person(){Name="王二", Age = 32, Address="高新区"},
                    });
                    logger.LogWarning("array:{arr}",new int[] { 1,2,3,4});
                    logger.LogWarning("dictionary:{dic}", new Dictionary<string, int>()
                    {
                        {"key1",1},
                        {"key2",2 },
                        {"key3",3 }
                    });

                    var person = new Person() { Name = "张三", Age = 18, Address = "金水区" };
                    logger.LogError("Person1:{person}", person);
                    logger.LogError("Person2:{@person}", person);

                    logger.LogCritical("animal:{animal}", new { name="tigger",size=18 });
                    logger.LogCritical("animal:{@animal}", new { name = "tigger", size = 18 });

                    logger.LogInformation("添加账号:{0},密码：{1}","admin","aaa");
                    logger.LogInformation("admin添加账户信息:{user}",new {name="aaa",pwd="bc2024",age=18,job="programmer" });

                    Thread.Sleep(1000);
                    index++;     
                }
            });
        }

       public class Person
        {
            public string Name { get; set; }

            public int Age { get; set; }

            public string Address { get; set; }
        }
    }
}
